<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"          			
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      >
    <ui:composition template="TaskProLayout.xhtml">
        <ui:define name="content"> 
            <div class="Post">
              <h:form id="addStudentForm" rendered="#{userBean.isAdd}">   
            <h:panelGrid columns="2" styleClass="gridCenter">
                <h:outputText value="Login" />
                <p:inputText value="#{userBean.newUser.login}" />       
                <h:outputLabel for="pwd1" value="Password" />  
                <p:password id="pwd1" value="#{userBean.newUser.password}" feedback="true" match="pwd2" label="Password 1" required="true"/>  
                <h:outputLabel for="pwd2" value="Retype password" />  
                <p:password id="pwd2" value="#{userBean.newUser.password}" feedback="false" label="Password retype" required="true"/>  
                <h:outputText value="Name" />
                <p:inputText value="#{userBean.newUser.name}" />
                <h:outputText value="Surname" />
                <p:inputText value="#{userBean.newUser.surname}" />
                <h:outputText value="E-mail" />
                <p:inputText value="#{userBean.newUser.email}" />
                <h:outputText value="State" />

                <h:selectOneMenu id="statusAdd" value="#{userBean.stateOfUser}" >  
                    <f:selectItem itemValue="student" itemLabel="student" />
                    <f:selectItem itemValue="teacher" itemLabel="teacher" />
                    <f:selectItem itemValue="admin" itemLabel="admin" />
                </h:selectOneMenu>
                <h:outputText value=" " />
                <p:commandButton value="Add User" action="#{userBean.addUser}" ajax="false"></p:commandButton>
            </h:panelGrid>
        </h:form>
            </div>
            
        <h:form id="studentForm" >
            <p:notificationBar position="top" effect="slide"  widgetVar="bar" styleClass="top">  
                <h:outputText value="System start with import this action could take a few second or minutes depend on number of users" style="color:#FFCC00;font-size:36px;" />  
            </p:notificationBar>
             <div class="Post">
            <p:dataTable id="studentsToAdd" rendered="#{userBean.displayPreview}"
                         rowKey="" var="user" emptyMessage="No studets to import"
                         paginator="true" paginatorAlwaysVisible="false" value="#{userBean.users}"
                         rows="40"
                         >
                <f:facet name="header">
                    <h:outputText value="Users to add"/>
                </f:facet>
                <p:column headerText="Login" >
                    <p:cellEditor>  
                        <f:facet name="output">  
                            <h:outputText value="#{user.login}" />  
                        </f:facet>  
                        <f:facet name="input">  
                            <h:inputText value="#{user.login}" />
                        </f:facet>  
                    </p:cellEditor>  
                </p:column>  
                <p:column headerText="Name" >
                    <p:cellEditor>  
                        <f:facet name="output">  
                            <h:outputText value="#{user.name}" />  
                        </f:facet>  
                        <f:facet name="input">  
                            <h:inputText value="#{user.name}" />
                        </f:facet>  
                    </p:cellEditor>  
                </p:column>     
                <p:column headerText="Surname" >
                    <p:cellEditor>  
                        <f:facet name="output">  
                            <h:outputText value="#{user.surname}" />  
                        </f:facet>  
                        <f:facet name="input">  
                            <h:inputText value="#{user.surname}" />
                        </f:facet>  
                    </p:cellEditor>  
                </p:column>     >
                <p:column headerText="E-mail" >
                    <p:cellEditor>  
                        <f:facet name="output">  
                            <h:outputText value="#{user.email}" />  
                        </f:facet>  
                        <f:facet name="input">  
                            <h:inputText value="#{user.email}" />
                        </f:facet>  
                    </p:cellEditor>  
                </p:column>     
                <p:column headerText="Edit" >

                    <p:rowEditor />  
                </p:column>   
                  <p:column headerText="Remove" >

                    <p:commandButton value="remove" action="#{userBean.removeFromList(user)}" update=":studentForm:studentsToAdd" ajax="false" />   
                </p:column> 
            </p:dataTable>
             </div>
            <div class="Post">
            <h:panelGrid columns="1"  rendered="#{userBean.isImport}" styleClass="gridCenter">
                <p:fileUpload  id="Upload" invalidFileMessage="This type of file is not permitted. Choose CVS or XLS files." label="Choose file with users" 
                               uploadLabel="Upload and preview"  cancelLabel="Cancel" fileUploadListener="#{userBean.addUserFromFile}"    update="studentForm" allowTypes="/(\.|\/)(csv|xls)$/"  mode="advanced"   />      
                <h:outputLabel for="Upload" value="Import users *.csv;*.xsl" />
            </h:panelGrid>
            </div>
            <div class="Post">
             <p:commandButton  value="Add to system" onclick="bar.show()" oncomplete="bar.hide()" rendered="#{userBean.displayPreview}" action="#{userBean.addUsersFromFile()}" ajax="false"/>       
            </div>
        </h:form> 
</ui:define>
    </ui:composition>
</html>